package com.jt.tenant.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.jt.tenant.R;
import com.jt.tenant.app.JTApplication;
import com.jt.tenant.fragment.HomeFragment;

/**
 * Created by yzf on 2016/2/15.
 */
public class ShockReportActivity extends JTActivity implements View.OnClickListener {

    private TextView title_name1, shock_location;

    private TextView shock_time;

    private TextView shock_value;

    private TextView shock_alter;

    private TextView shock_address;

    private TextView binding_equip;

    private String m_shock_time;

    private int mValue;

    private String lon, lat;

    private boolean isExit = false;

    private boolean isBack = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_shock_report);

        mValue = Integer.valueOf(getIntent().getStringExtra("value"));

        lon = getIntent().getStringExtra("lon");

        lat = getIntent().getStringExtra("lat");

        m_shock_time = getIntent().getStringExtra("create_time");

        init_view();

    }

    private void init_view() {

        (title_name1 = (TextView) findViewById(R.id.tv_title_name)).setText("震动提醒");

        (shock_location = (TextView) findViewById(R.id.tv_shock_location)).setOnClickListener(this);

        (shock_time = (TextView) findViewById(R.id.shock_time)).setText("您的爱车于" + m_shock_time + "发生震动");

        (shock_value = (TextView) findViewById(R.id.shock_value)).setText(getIntent().getStringExtra("value"));

        shock_alter = (TextView) findViewById(R.id.shock_alter);

        if (mValue <= 25) {

            shock_alter.setText("轻微碰撞，请留意");

        } else if (mValue > 25 && mValue <= 50) {

            shock_alter.setText("中度碰撞，请留意");

        } else if (mValue > 50 && mValue <= 75) {

            shock_alter.setText("重度碰撞，请及时查看");

        } else if (mValue >= 25) {

            shock_alter.setText("严重碰撞，请及时查看");
        }

        (shock_address = (TextView) findViewById(R.id.shock_address)).setText(getIntent().getStringExtra("address"));

    }

    @Override
    public void onClick(View view) {
        super.onClick(view);

        switch (view.getId()){

            case R.id.tv_shock_location:

                startActivity(new Intent(ShockReportActivity.this, CarLocationActivity.class)

                        .putExtra("location", "碰撞地点")

                        .putExtra("longitude", lon)

                        .putExtra("latitude", lat)
                );

                break;

        }


    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

        if (HomeFragment.onDismiss == null || !HomeFragment.onDismiss.onDismiss()) {

            if (keyCode == KeyEvent.KEYCODE_BACK) {

                if (isBack) {

                    if (isExit == false) {

                        isExit = true;

                        Toast.makeText(ShockReportActivity.this, "再按一次退出!", Toast.LENGTH_SHORT).show();

                        Handler mHandler = new Handler() {
                            @Override
                            public void handleMessage(Message msg) {

                                super.handleMessage(msg);

                                isExit = false;

                            }
                        };
                        mHandler.sendEmptyMessageDelayed(0, 3000);

                        return true;

                    } else {

                        JTApplication.INSTANCE.AppExit(context);

                        return false;

                    }
                } else {
                    finish();
                }


            }

        }

        return true;
    }

    @Override
    public void onBack(View v) {
//        super.onBack(v);
        if (isBack) {
            if (isExit == false) {

                isExit = true;

                Toast.makeText(ShockReportActivity.this, "再按一次退出!", Toast.LENGTH_SHORT).show();

                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {

                        super.handleMessage(msg);

                        isExit = false;

                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 3000);

//                return true;

            } else {

                JTApplication.INSTANCE.AppExit(context);

//                return false;

            }
        } else {
            finish();
        }
    }

}
